Number.prototype.times=function(f){for(var i=0;i<this;i++) f();}
Array.prototype.each = function(fn) {
	for (var i = 0,	j = this.length; i < j; i++) fn(this[i]);
	return this;
}
Array.prototype.map = function(fn){
	for (var i = 0,	j = this.length; i < j; i++) this[i] = fn(this[i]);
	return this;
}
Array.prototype.has = function(nd) {
	var L = this.length;
	while (L--) if (this[L] === nd) return true;
	return false;
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g, "");
}
String.prototype.addS = function() {
	return this.replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
}
String.prototype.stripS = function() {
	return this.replace(/\\(.?)/g,
	function(s, n1) {
		switch (n1) {
		case '\\':
			return '\\';
		case '0':
			return '\u0000';
		case '':
			return '';
		default:
			return n1;
		}
	});
}
String.prototype.stripTags = function() {
	return this.replace(/<\/?[^>]+>/gi, '');
}
(funciton(undefined){
	var WX={
		_type_:'WX'
		,version:0.1
		,isIE:navigator.appVersion.indexOf("MSIE") != -1 ? true: false
		,try:function(){
			for (var i=0,l=arguments.length;i<l;i++){
				try{
					return arguments[i]();
				}catch(e){}
			}
		}
		,et:function(to, from) {
			if (to._type_===from._type_ && to._type_!==undefined) return to;
			var p;
			for (p in from) try {
				to[p] = from[p];
			} catch(e) {}
			return to;
		}
		,A:function(I) {
			if (!I) return [];
			if (I.toArray) return I.toArray();
			var L = I.length,
			R = new Array(L);
			while (L--) R[L] = I[L];
			return R;
		}
		,txt2json:function(txt){
		    return eval('('+txt+')');
		}
		,rgb2hex:function(r,g,b){
			r=r.toString(16);if(r.length==1) r='0' + r;
			g=g.toString(16);if(g.length==1) g='0' + g;
			b=b.toString(16);if(b.length==1) b='0' + b;
			return "#" + r + g + b;
		}
		,hex2rgb:function(a,ifArr){
			var R,G,B;
			if(a.length==4){
				R=parseInt(a.substr(1,1),16),G=parseInt(a.substr(2,1),16),B=parseInt(a.substr(3,1),16);
				R=R*16+R,G=G*16+G,B=B*16+B;
			}else{
				R=parseInt(a.substr(1,2),16),G=parseInt(a.substr(3,2),16),B=parseInt(a.substr(5,2),16);
			}
			return ifArr?[R,G,B]:"rgb("+R+","+G+","+B+")";
		}
		,ev:{
			_type_:'ev'
			,add:function(elm,evName,fn){
				if (elm.addEventListener) {
					elm.addEventListener(evName, fn, false);
				} else if (obj.attachEvent) {
					elm.attachEvent("on" + evName, fn);
				} else {}
			}
			,remove:function(elm, evName, fn) {
				try {
					elm.detachEvent("on" + evName, fn);
				} catch(e) {
					try {
						elm.removeEventListener(evName, fn, true);
					} catch(e) {
						elm["on" + evName] = null;
					}
				}
			}
			,stop:function(e) {
				e = e || window.event;
				try {
					e.stopPropagation();
					e.preventDefault();
				} catch(e) {
					try {
						e.cancelBubble = true;
						e.returnValue = false;
					} catch(e) {}
				}
			}
			,target:function(e) {
				return window.event ? window.event.srcElement: e.target;
			}
			,getPointerPosition:function(e) {//兼容浏览器的鼠标x,y获得函数
			    e=e||window.event;
			    var x = e.pageX||(e.clientX+(document.documentElement.scrollLeft||document.body.scrollLeft)),
				y = e.pageY||(e.clientY+(document.documentElement.scrollTop||document.body.scrollTop));
				return {'x':x,'y':y};
			}
		}
		,Elm:{
			_type_:'Elm'
			,et:function(f){
				return WX.et(this,f);
			}
			,create:function(tag,attr){
				var k,elm=document.createElement(tag);
				for(k in attr)
					elm[k]=attr[k];
				return WX.et(elm,WX.Elm);
			}
			,prev:function(n){
				var x=this.previousSibling;
				if(x){
					if(!n) while (x.nodeType!=1&&x.previousSibling) x=x.previousSibling;
					return WX.et(x,this);
				}
			}
			,next:function(n){
				var x=this.nextSibling;
				if(x){
					if(!n) while (x.nodeType!=1&&x.nextSibling) x=x.nextSibling;
					return WX.et(x,this);
				}
			}
			,ap:function(elm){
				this.appendChild(elm);
				return this;
			}
			,rmc:function(elm){
				this.removeChild(elm);
				return this;
			}
			,addbefore:function(elm){
				this.parentNode.insertBefore(elm,this);
				return this;
			}
			,addafter:function(elm){
				if(this.next()) this.next().addbefore(elm);
				else this.parentNode.appendChild(elm);
				return this;
			}
			,addwrap:function(elm){
				this.rep(elm);
				elm.ap(this);
				return this;
			}
			,hide:function(){
				this.style.display='none';
				return this;
			}
			,show:function(){
				this.style.display='';
				return this;
			}
			,toggle:function(){
				this.style.display=='none'?this.style.display='':this.style.display='none';
				return this;
			}
			,destroy:function(){
				this.parentNode.removeChild(this);
			}
			,rep:function(elm){
				this.addbefore(elm);
				this.destroy();
				return WX.et(elm,this);
			}
			,childs:function(){
				var i,L,rs=[],cs=this.children;
				for(i=0,L=cs.length;i<L;i++) rs.push(WX.et(cs[i],this));
				return rs;
			}
			,getAttr:function(k){
				return this.getAttribute(k);
			}
			,setAttr:function(k,v){
				this.setAttribute(k,v);
				return this;
			}
			,setStyle:function(style){//style:匿名对象
				var p;
				for(p in style)
					this.style[p]=style[p];
				return this;
			}
			,setOuterHtml:function(html) {
				var r = document.createRange();
				this.innerHTML = html;
				r.selectNodeContents(this);
				return this.rep(WX.et(r.extractContents(),this));
			}
			,setFloat:function(v){
				this.style.styleFloat?this.style.styleFloat=v:this.style.cssFloat=v;
				return this;
			}
			,getFloat:function(){
				return this.style.styleFloat?this.style.styleFloat:this.style.cssFloat;
			}
			,setOpacity:function(level) {
				this.filters ? this.style.filter = 'alpha(opacity=' + level * 100 + ')' : this.style.opacity = level;
				return this;
			}
			,withAttr:function(k,xpr,v,elm){
				elm = elm||this;
				switch (xpr)) {/*=~^$!*/
					case '=':
						if (v==elm.getAttribute(k)) return true;
						break;
					case '^':
						if (elm.getAttribute(k).indexOf(v) == 0) return true;
						break;
					case '$':
						if (elm.getAttribute(k).substr(-v.length) == v) return true;
						break;
					case '~':
						if (elm.getAttribute(k).indexOf(v) != -1) return true;
						break;
					case '!':
						if (elm.getAttribute(k).indexOf(v) == -1) return true;
						break;
				}
				return false;
			}
			,getBgColor:function(ifRGB){
				var c,rgb;
				while(this){
					if (window.getComputedStyle) c=window.getComputedStyle(this,null).getPropertyValue("background-color");
					if (this.currentStyle) c=this.currentStyle.backgroundColor;
					if ((c!="" && c.toLowCase()!="transparent")||this.tagName.toLowCase()=="body"){break;}
					this=this.parentNode;
				}
				if (c==undefined||c==""||c.toLowCase()=="transparent") c="#FFFFFF";
				rgb=c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
				return ifRGB?(rgb?c:WX.hex2rgb(c)):(rgb?WX.rgb2hex(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3])):c);
			}
		}
		,trElm:{
			_type_:'trElm'
			,addtd:function(){
				return WX.et(this.insertCell(0),WX.Elm);
			}
			,additems:function(items){
				var l=items.length;
				while(l--)
					this.addtd().innerHTML=items[l];
				return this;
			}
		}
		,tableElm:{
			_type_:'tableElm'
			,addtr:function(){
				return WX.et(this.insertRow(0),WX.Elm).et(WX.trElm);
			}
			,clear:function(){
				var l=this.rows.length;
				while(l--)this.deleteRow(l);
			}
		}
		,$:function(xpr,doc){//#x[k=~v],...
			var doc = doc||document, xprs = xpr.split(',').map(function(s){return s.trim()}), r=[];
			for(var I=0,L=xprs.length; I<L; I++){
				var p1=xprs[I].indexOf('[')
					,p2=xprs[I].indexOf('=')
					,p3=xprs[I].indexOf(']')
					,k,v,t,x;
				if (p1>0 && p2>(p1+1) && p3>(p2+2)) {
					t=xprs[I].substring(0,p1);
					k=xprs[I].substring(p1+1,p2);
					v=xprs[I].substring(p2+2,p3);
					x=xprs[I].substr(p2+1,1);
				}else{
					t=xprs[I];
				}
				switch(t.substr(0,1)){
					case '#':
						var elm = doc.getElementById(t.substr(1));
						if (elm) {
							if(k && p1>1){
								if(WX.Elm.withAttr(k,x,v,elm)){
									r.push(WX.et(elm,WX.Elm));
								}
							}else{
								r.push(WX.et(elm,WX.Elm));
							}
						}
						break;
					case '.':
						var txt=t.substr(1),elms=doc.getElementsByClassName?doc.getElementsByClassName(txt):doc.getElementsByTagName('*')||doc.all||document.all;
						for(var i=0,l=elms.length;i<l;i++)
							if ((" "+elms[i].className+" ").indexOf(" "+txt+" ")!=-1) {
								if(k && p1>1){
									if(WX.Elm.withAttr(k,x,v,elms[i])){
										r.push(WX.et(elms[i],WX.Elm));
									}
								}else{
									r.push(WX.et(elms[i],WX.Elm));
								}
							}
						break;
					default:
						var elms = WX.A(doc.getElementsByTagName(t));
						for(var i=0,l=elms.length;i<l;i++){
							if(k){
								if(WX.Elm.withAttr(k,x,v,elms[i])){
									r.push(WX.et(elms[i],WX.Elm));
								}
							}else{
								r.push(WX.et(elms[i],WX.Elm));
							}
						}
				}
			}
			return r;
		}
		,script:{
			_type_:'script'
			,load:function(src,loaded,charset,doc){
				doc = doc||document;
				var elm = doc.createElement("script");
				WX.et(elm,{async:true,charset:charset||"utf-8",type:"text/javascript"});
				elm.onload = elm.onreadystatechange = function(){
					if (!elm.readyState || /loaded|complete/.test(elm.readyState)) {
						elm.onload = elm.onreadystatechange = null;
						if (elm.parentNode)
							elm.parentNode.removeChild(elm);
						elm = null;
						if(loaded)
							loaded();
					}
				};
				elm.src = src;
				doc.getElementsByTagName("head")[0].appendChild(elm);
			}
		}
	};
	window.WX=WX;
})();